# 导入fastapi包
from fastapi import FastAPI, Header, Body, Form
import uvicorn

app = FastAPI()


# 传参方式：1：可以通过url传参 用python的f表达式
@app.get("/user/{id}")
def get_user(id):
    return {"id": id}


# 2:传统的query string
# ?id=2
@app.get("/user2")
def get_user2(id, token=Header(None)):
    return {"id": id, "token": token}


@app.post("/login")
# def login(data=Body(None)): # 不支持
def login(username=Form(None), password=Form(None)):
    return {"data:": {"username": username, "password": password} }


if __name__ == '__main__':
    uvicorn.run(app)
